package auths

import (
	"context"
	"gitee.com/lailonghui/vehicle-supervision-framework/pkg/enums/org_enum"
	"gitee.com/lailonghui/vehicle-supervision-framework/pkg/enums/sys_enum"
)

// 用户信息
type UserInfo struct {
	// 姓名
	Name string
	// 用户名
	Username string

	// 用户ID
	UserId string

	// 部门ID
	DepartmentId string

	// 部门ID列表(包含当前部门ID和子部门)
	DepartmentIds []string

	// 组织ID
	OrganizationId string

	// 组织ID列表(包含当前组织和子组织)
	OrganizationIds []string

	// 组织类型
	OrganizationType int

	// 数据权限范围
	DataAccess int

	// 省份ID
	ProvinceId string

	// 市ID
	CityId string

	// 县ID
	AreaId string

	// 角色ID
	RoleId string

	// 登录的业务系统
	System int
}

// 获取用户信息
func GetUser(ctx context.Context) *UserInfo {
	value, ok := ctx.Value(USER_INFO_KEY).(*UserInfo)
	if !ok {
		// TODO 现阶段，如果context中没有用户，则返回默认的用户信息
		return &UserInfo{
			Name:             "testName",
			UserId:           "testUser",
			DepartmentId:     "testDepartment",
			DepartmentIds:    []string{"testDepartment", "testDepartment2"},
			OrganizationId:   "testOrganization",
			OrganizationIds:  []string{"testOrganization", "testOrganization2"},
			ProvinceId:       "3322777764872704",
			CityId:           "3322777766742528",
			AreaId:           "3322777766769152",
			OrganizationType: org_enum.OrgOrganizationCategory.TransportEnterprise(),
			DataAccess:       sys_enum.SysUserGrade.DataAccessAll(),
			RoleId:           "admin",
			System:           1,
			Username:         "testUsername",
		}
	}
	return value
}

// 获取用户ID
func GetUserId(ctx context.Context) *string {
	user := GetUser(ctx)
	if user == nil {
		return nil
	}
	return &user.UserId
}
